package com.ww.springboot.dd.dto;

import org.springframework.util.StringUtils;

public class TenantContext {
    public static final String KEY_TID = "tenantId";
    public static final String KEY_TOKEN = "Blade-Auth";

    private TenantContext() {
    }

    public static String getTID() {
        String tid = (String) ThreadLocalUtil.get("tenantId");
        if (!StringUtils.isEmpty(tid)) {
            return tid;
        } else {
            return null;
        }
    }

    public static void bind(String tid) {
        ThreadLocalUtil.put("tenantId", tid);
    }

    public static String unbind() {
        String tid = (String) ThreadLocalUtil.getAndRemove("tenantId");
        return tid;
    }
}